<template>
  <div>
    <el-row>
      <!-- 放搜索条件 
              :inline="ture"让表单元素占一行,一行不够会换行-->
      <el-form :inline="true">
        <el-col :span="24">
          <el-form-item label="来访人电话">
            <el-input v-model="pdParam.lfTel" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="来访人姓名">
            <el-input v-model="pdParam.lfName" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
        <el-form-item label="受访老人">
          <el-input v-model="pdParam.userName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="来访状态" label-width="100px" prop="jdPersonId">
          <el-select v-model="pdParam.lfstatus" placeholder="请选择">
            <el-option label="待来访" value="0"></el-option>
            <el-option label="已完成来访" value="1"></el-option>
            <el-option label="探视中" value="2"></el-option>
            <el-option label="来访失败" value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="clear">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="queryEmployee">查询</el-button>
        </el-form-item>
      </el-col>
      </el-form>

      <el-col :span="24">
        <!-- 放表格数据 -->
        <el-button type="danger" @click="addLf">新增</el-button>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="id" label="id"></el-table-column>
          <el-table-column prop="userName" label="受访老人"></el-table-column>
          <el-table-column prop="lfTime" label="来访日期"></el-table-column>
          <el-table-column prop="lfName" label="来访人"></el-table-column>
          <el-table-column
            prop="lfIdentity"
            label="来访人身份证"
          ></el-table-column>
          <el-table-column label="操作" width="300">
            <template slot-scope="scope">
              <el-button class="el-button--primary" @click="update(scope.row)"
                >编辑</el-button
              >
              <el-button class="el-button--danger" @click="del(scope.row.id)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="12">
        <!-- 放分页部分 -->
        <el-pagination
          background
          :page-sizes="[3, 5, 10, 20]"
          :page-size="pageSize"
          :current-page="pageNum"
          layout="total, sizes, prev, pager, next"
          @next-click="nextPage"
          @prev-click="prevPage"
          @size-change="sizeChange"
          @current-change="currentPage"
          :total="total"
        ></el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
    
    <script>
export default {
  data() {
    return {
      dicts: [],
      olders: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,

      pdParam: {
        lfTel: "",
        lfName: "",
        lfstatus: "",
        userName: "",
      },
      tableData: [],
    };
  },
  methods: {
    del(val) {
      this.$confirm("确认删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios.get("api/register/deleteLf/" + val).then((res) => {
            if (res.data.code == 200) {
              //发删除请求
              this.$message.success("删除成功!");
              this.queryUser();
            }
          });
        })
        .catch(() => {});
    },
    update(val) {
      this.$router.push({ path: "/updateLf", query: { form: val } });
    },

    addLf() {
      this.$router.push({ path: "/lfAdd" });
    },
    clear() {
      this.pdParam = {};
    },
    prevPage(val) {
      //点击上一页触发
      this.pageNum = val;
      this.queryEmployee();
    },
    nextPage(val) {
      //点击下一页触发
      this.pageNum = val;
      this.queryEmployee();
    },
    sizeChange(val) {
      //val每一页条数
      this.pageNum = 1;
      this.pageSize = val;
      this.queryEmployee();
    },
    currentPage(val) {
      this.pageNum = val;
      this.queryEmployee();
    },
    queryCondition() {
      thispageNum = 1;
      this.queryEmployee();
    },
    queryEmployee() {
      //带分页参数pageNum,pageSize
      let pageParam = {};
      pageParam.pageNum = this.pageNum;
      pageParam.pageSize = this.pageSize;
      pageParam.param = this.pdParam;
      this.$axios.post("api/register/queryLFList", pageParam).then((res) => {
        if (res.data.code == 200) {
          let pageData = res.data.data;
          this.tableData = pageData.list;
          //给分页参数赋值
          this.total = pageData.total;
          this.pageNum = pageData.pageNum;
          this.pageSize = pageData.pageSize;
        } else {
          this.$router.push({ path: "/login" });
        }
      });
    },
  },
  created() {
    this.queryEmployee();
  },
};
</script>
    
    <style scoped></style>